package com.bt.lms.ui.page.teaching.supervise;

import com.bt.lms.ui.action.teaching.supervise.LookStuBtnAction;
import com.bt.lms.ui.vo.CoursewareInfo;
import com.bt.lms.ui.page.teaching.supervise.action.RealTimeClassBtn;
import com.bt.lms.ui.page.teaching.supervise.action.TeachingCheckBtn;
import com.bt.lms.ui.page.teaching.supervise.action.GradeBtn;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 查看课程资源界面
 */
public class PageLookCourseResource extends VBox {

    /**
     * 查看课程资源界面长
     */
    private double preWidth = 1280;
    /**
     * 查看课程资源界面高
     */
    private double preHeight = 800;

    /**
     *列名默认长度
     */
    private double columnPreWidth = 100;

    public PageLookCourseResource(){

        this.setPrefSize(preWidth,preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);

        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //按钮横向盒子
        HBox buttonHBox = new HBox();
        initButtonHBox(buttonHBox);
        //具体课程资源盒子
        HBox detailCourseHBox = new HBox();
        initDetailCourseHBox(detailCourseHBox);
        //搜索区域横向盒子
        HBox searchHBox = new HBox();
        initSearchHBox(searchHBox);
        //表格盒子
        VBox tableVBox = new VBox();
        initTableVBox(tableVBox);
        //页码横向盒子
        HBox pageNumHBox = new HBox();
        initPageNumHBox(pageNumHBox);


        ObservableList<Node> children = this.getChildren();
        children.addAll(topHBox,buttonHBox,detailCourseHBox,searchHBox,tableVBox,pageNumHBox);
    }



    /**
     * 页码横向盒子
     * @param pageNumHBox
     */
    private void initPageNumHBox(HBox pageNumHBox) {
        pageNumHBox.setSpacing(20);
        pageNumHBox.setPadding(new Insets(10));
        pageNumHBox.setAlignment(Pos.CENTER_RIGHT);
        //首页标签
        Label homeLab = new Label("<<首页");
        homeLab.setTextFill(Color.rgb(108,221,83));
        homeLab.setFont(new Font(20));
        //上一页标签
        Label previousPageLab = new Label("<<上一页");
        previousPageLab.setTextFill(Color.rgb(108,221,83));
        previousPageLab.setFont(new Font(20));
        //第一页按钮
        Button onePageBtn = new Button("1");
        onePageBtn.setPrefWidth(27);
        onePageBtn.setPrefHeight(30);
        //第二页按钮
        Button twoPageBtn = new Button("2");
        twoPageBtn.setPrefWidth(27);
        twoPageBtn.setPrefHeight(30);
        //第三页按钮
        Button threePageBtn = new Button("3");
        threePageBtn.setPrefWidth(27);
        threePageBtn.setPrefHeight(30);
        //第四页按钮
        Button fourPageBtn = new Button("4");
        fourPageBtn.setPrefWidth(27);
        fourPageBtn.setPrefHeight(30);
        //下一页标签
        Label nextPageLab = new Label("下一页>>");
        nextPageLab.setFont(new Font(20));
        nextPageLab.setTextFill(Color.rgb(108,221,83));
        //尾页标签
        Label endPageLab = new Label("尾页>>");
        endPageLab.setFont(new Font(20));
        endPageLab.setTextFill(Color.rgb(108,221,83));
        //总记录数条
        Label totalPageLab = new Label("总页数100条");
        totalPageLab.setFont(new Font(20));
        totalPageLab.setTextFill(Color.rgb(255,65,55));
        //条数文本框
        TextField countTF = new TextField();
        countTF.setPrefWidth(100);
        // /10标签
        Label tenLab = new Label("/10");
        tenLab.setFont(new Font(20));
        //GO按钮
        Button goBtn = new Button("GO");
        ObservableList<Node> children = pageNumHBox.getChildren();
        children.addAll(homeLab,previousPageLab,onePageBtn,twoPageBtn,threePageBtn,fourPageBtn,nextPageLab,endPageLab,totalPageLab,countTF,tenLab,goBtn);
    }

    /**
     * 表格盒子
     * @param tableVBox
     */
    private void initTableVBox(VBox tableVBox) {

        //表格
        TableView tableView = new TableView<>();

        //列
        TableColumn coursewareNameColumn = new TableColumn<>("课件名称");
        coursewareNameColumn.setPrefWidth(columnPreWidth);
        TableColumn coursewareNumColumn = new TableColumn<>("课件编号");
        coursewareNumColumn.setPrefWidth(columnPreWidth);
        TableColumn coursewareTypeColumn = new TableColumn<>("课件类型");
        coursewareTypeColumn.setPrefWidth(columnPreWidth);
        TableColumn minuteColumn = new TableColumn<>("时长（分钟）");
        minuteColumn.setPrefWidth(columnPreWidth);
        TableColumn languageColumn = new TableColumn<>("语种");
        languageColumn.setPrefWidth(columnPreWidth);
        TableColumn contributorColumn = new TableColumn<>("贡献者");
        contributorColumn.setPrefWidth(columnPreWidth);
        TableColumn onlineTimeColumn = new TableColumn<>("上线时间");
        onlineTimeColumn.setPrefWidth(columnPreWidth+columnPreWidth);
        TableColumn learningPeopleColumn = new TableColumn<>("学习人数");
        learningPeopleColumn.setPrefWidth(columnPreWidth);
        TableColumn finishPeopleColumn = new TableColumn<>("完成人数");
        finishPeopleColumn.setPrefWidth(columnPreWidth);

        //模拟表中数据
        CoursewareInfo coursewareInfo1 = new CoursewareInfo("【大学语文】","CNM344425","标准课件","40","中文","王老师","2012-05-03 12：34","5","3");
        CoursewareInfo coursewareInfo2 = new CoursewareInfo("【大学数学】","Match35354","标准课件","50","中文","张老师","2012-06-03 12：00","10","3");
        CoursewareInfo coursewareInfo3 = new CoursewareInfo("【大学英语】","Eng353132","标准课件","60","英语","周老师","2012-07-03 12：00","20","10");

        //数据集合
        List<CoursewareInfo>coursewareInfoList = new ArrayList<>();
        coursewareInfoList.add(coursewareInfo1);
        coursewareInfoList.add(coursewareInfo2);
        coursewareInfoList.add(coursewareInfo3);
        //将数据集合转换成Javafx组件集合
        ObservableList<CoursewareInfo>coursewareInfos = FXCollections.observableArrayList(coursewareInfoList);
        tableView.setItems(coursewareInfos);

        //映射到表中
        coursewareNameColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("coursewareName"));
        coursewareNumColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("coursewareNum"));
        coursewareTypeColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("coursewareType"));
        minuteColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("minute"));
        languageColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("language"));
        contributorColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("contributor"));
        onlineTimeColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("onlineTime"));
        learningPeopleColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("learningPeople"));
        finishPeopleColumn.setCellValueFactory(new PropertyValueFactory<CoursewareInfo,String>("finishPeople"));



        tableVBox.getChildren().add(tableView);

        tableView.getColumns().addAll(coursewareNameColumn,coursewareNumColumn,coursewareTypeColumn,minuteColumn,languageColumn,contributorColumn,onlineTimeColumn,learningPeopleColumn,finishPeopleColumn);






    }

    /**
     * 搜索区域横向盒子
     * @param searchHBox
     */
    private void initSearchHBox(HBox searchHBox) {
        searchHBox.setPadding(new Insets(5));
        searchHBox.setSpacing(20);
        //下拉框
        ComboBox coursewareTypeCB = new ComboBox<>();
        coursewareTypeCB.getItems().add("课件类型");
        coursewareTypeCB.getItems().add("标准课件");
        coursewareTypeCB.getItems().add("非标准课件");
        coursewareTypeCB.getSelectionModel().selectFirst();
        //文本框
        TextField coursewareTypeTF = new TextField();
        //搜索按钮
        Button searchBtn = new Button("搜索");
        searchHBox.getChildren().addAll(coursewareTypeCB,coursewareTypeTF,searchBtn);
    }

    /**
     * 具体课程资源横向盒子
     * @param detailCourseHBox
     */
    private void initDetailCourseHBox(HBox detailCourseHBox) {
        detailCourseHBox.setPadding(new Insets(10));
        //课件资源按钮
        Button coursewareResourceBtn = new Button("课件资源");
        BackgroundFill backgroundFill = new BackgroundFill(Paint.valueOf("#2D82C5"),null,null);
        Background background = new Background(backgroundFill);
        coursewareResourceBtn.setBackground(background);
        detailCourseHBox.getChildren().add(coursewareResourceBtn);
    }

    /**
     * 按钮横向盒子
     * @param buttonHBox
     */
    private void initButtonHBox(HBox buttonHBox) {

        buttonHBox.setSpacing(20);
        buttonHBox.setPadding(new Insets(10));
        //查看学员按钮
        Button lookStuBtn = new Button("查看学员");
        LookStuBtnAction lookStuBtnAction = new LookStuBtnAction();
        lookStuBtn.setOnAction(lookStuBtnAction);
        //查看课程资源按钮
        Button lookCourseResourceBtn = new Button("查看课程资源");
        ObservableList<Node> children = buttonHBox.getChildren();
        children.addAll(lookStuBtn,lookCourseResourceBtn);

        //教师值机按钮
        Button teachingCheckBtn = new Button("教师值机管理");
        ObservableList<Node> teachingCheckBtnChildren = buttonHBox.getChildren();
        teachingCheckBtnChildren.add(teachingCheckBtn);
        //事件
        TeachingCheckBtn teachingCheckBtnAction = new TeachingCheckBtn();
        teachingCheckBtn.setOnAction(teachingCheckBtnAction);

        //实时课堂按钮
        Button realTimeClassBtn = new Button("实时课堂管理");
        ObservableList<Node> realTimeClassBtnChildren = buttonHBox.getChildren();
        realTimeClassBtnChildren.add(realTimeClassBtn);
        RealTimeClassBtn realTimeClassBtnAction = new RealTimeClassBtn();
        realTimeClassBtn.setOnAction(realTimeClassBtnAction);

        //成绩及结业按钮
        Button gradeBtn = new Button("成绩及结业管理");
        ObservableList<Node> gradeBtnChildren = buttonHBox.getChildren();
        gradeBtnChildren.add(gradeBtn);
        GradeBtn gradeBtnBtnAction = new GradeBtn();
        gradeBtn.setOnAction(gradeBtnBtnAction);
    }

    /**
     * 顶部横向盒子
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(5));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学监督>实施中的教学安排>查看课程资源");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }
}
